package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import utils.AirTransportRepositoryManager;

public class Cancellation_ResultController extends AbstractController {

	private AirTransportRepositoryManager repositoryManager;
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

		String flightid = request.getParameter("flightid");
		String jmbg = request.getParameter("jmbg");
		
		ModelAndView mav =  new ModelAndView();
		mav.addObject("flight", repositoryManager.getFlightByID(flightid));
		mav.addObject("passenger", repositoryManager.getPassengerByJMBG(jmbg));
		
		if ( repositoryManager.cancel(flightid, jmbg) == true ) {
			mav.addObject("flag", true);
		}
		else {
			mav.addObject("flag", false);
		}

		return mav;
	}

	
	public AirTransportRepositoryManager getRepositoryManager() {
		return repositoryManager;
	}

	public void setRepositoryManager(AirTransportRepositoryManager repositoryManager) {
		this.repositoryManager = repositoryManager;
	}

}
